import {
  txList
} from '../../config/apiServe/new-rpc'
export default {
  props: {
    ListLength: {
      type: Number,
      default: 6
    }
  },
  data() {
    return {
      params: [{
        "sort": [{
          "key": "height",
          "ascending": false
        }],
        "page": {
          "number": 1,
          "size": this.ListLength
        }
      }],
      txList: []
    }
  },
  computed: {
    maxHeight() {
      return this.$store.state.maxHeight || 0;
    }
  },
  watch: {
    maxHeight() {
      this.getTxList()
    }
  },
  mounted() {
    this.init()
    this.getTxList()
  },
  methods: {
    init() {
      if (this.txList.length === 0) {
        let max = this.ListLength
        let initTxs = {
          hash: '',
          from: '',
          to: '',
          block_time: ''
        }
        while (max > 0) {
          this.txList.push(initTxs)
          max--
        }
      } else return
    },
    async getTxList() {
      const res = await txList(this.params)
      this.txList = res.result
    }
  }
}